#include <boost/multi_index_container.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index/member.hpp>
#include <iostream>
#include <string>
 
struct Person
{
    std::string m_name;
    int m_age;
 
    Person(const std::string &name, int age) : m_name(name), m_age(age) {}
};
 
typedef boost::multi_index::multi_index_container<
    Person,
    boost::multi_index::indexed_by<
        boost::multi_index::sequenced<>,       //* index 0
        boost::multi_index::ordered_non_unique< //* index 1
            boost::multi_index::member<Person, int, &Person::m_age>
        >,
        boost::multi_index::random_access<>    //* index 2
    >
> Person_multi;
 
 
 
int main()
{
    Person_multi persons;
 
    persons.push_back(Person("Euler",20));
    persons.push_back(Person("Gauss",21)); 
    persons.push_back(Person("Poincare",22));
 
    for(Person_multi::iterator it = persons.begin();it!=persons.end();++it)
        std::cout << it->m_name << " is " << it->m_age << std::endl;
 
    const Person_multi::nth_index<1>::type &age_index = persons.get<1>();
    Person_multi::nth_index<1>::type::iterator lower = age_index.lower_bound(20);
    Person_multi::nth_index<1>::type::iterator upper = age_index.upper_bound(30);
    for(; lower != upper; ++lower)
        std::cout << lower->m_name << std::endl;
 
    const Person_multi::nth_index<2>::type &random_access_index = persons.get<2>();
    for(unsigned int i = 0; i< random_access_index.size(); ++i)
        std::cout << random_access_index[i].m_name << std::endl;
 
}